package cn.study.vue_project_xxx.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.study.vue_project_xxx.common.result.ResultSet;
import cn.study.vue_project_xxx.entity.dto.RegisterUserDTO;
import cn.study.vue_project_xxx.entity.po.TAdmin;
import cn.study.vue_project_xxx.entity.po.UserInfo;
import cn.study.vue_project_xxx.service.UserService;
import cn.study.vue_project_xxx.util.PageParam;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    UserService userService;

    /**
     * 新增普通用户
     * @param registerUserDTO 普通用户信息
     * @return ResultSet
     */
    @PostMapping("/registerUserInfo")
    public ResultSet<Boolean> registerUserInfo(@RequestBody RegisterUserDTO registerUserDTO) {
        return ResultSet.success(userService.addUser(registerUserDTO));
    }

    /**
     * 删除普通用户
     * @param
     * @return ResultSet
     */
    @PostMapping("/deleteUserInfo")
    public ResultSet<Boolean> deleteUserInfo(@RequestParam List<Long> userIds) {
        return ResultSet.success(userService.deleteUser(userIds));
    }

    /**
     * 修改普通用户
     * @param registerUserDTO 普通用户信息
     * @return ResultSet
     */
    @PostMapping("/updateUserInfo")
    public ResultSet<Boolean> updateUserInfo(@RequestBody UserInfo registerUserDTO) {
        return ResultSet.success(userService.updateUser(registerUserDTO));
    }

    /**
     * 查询普通用户列表
     * @param
     * @return ResultSet
     */
    @PostMapping("/selectUsers")
    public ResultSet<Page<UserInfo>> selectUsers(@RequestParam List<Long> userIds, Integer currentPage, Integer pageSize) {
        Page<UserInfo> page = new Page<>(currentPage, pageSize);
        return ResultSet.success(userService.selectUsers(page,userIds));
    }



}
